package com.ruoyi.project.manhua.climb.controller;

import java.util.LinkedHashMap;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.manhua.climb.domain.MhClimb;
import com.ruoyi.project.manhua.climb.service.IMhClimbService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 漫画爬虫Controller
 *
 * @author yuan
 * @date 2021-02-10
 */
@Controller
@RequestMapping("/manhua/climb")
public class MhClimbController extends BaseController {
    private String prefix = "manhua/climb";

    @Autowired
    private IMhClimbService mhClimbService;



    @RequiresPermissions("manhua:climb:view")
    @GetMapping()
    public String climb(ModelMap map) {

        /*返回的数据*/
        LinkedHashMap<Long, String> mapMhNames = mhClimbService.mapMhNames();

        map.put("MhNameDataAll", mapMhNames);

        return prefix + "/climb";
    }

    /**
     * 查询漫画爬虫列表
     */
    @RequiresPermissions("manhua:climb:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MhClimb mhClimb) {
        startPage();
        List<MhClimb> list = mhClimbService.selectMhClimbList(mhClimb);
        return getDataTable(list);
    }

    /**
     * 导出漫画爬虫列表
     */
    @RequiresPermissions("manhua:climb:export")
    @Log(title = "漫画爬虫", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MhClimb mhClimb) {
        List<MhClimb> list = mhClimbService.selectMhClimbList(mhClimb);
        ExcelUtil<MhClimb> util = new ExcelUtil<MhClimb>(MhClimb.class);
        return util.exportExcel(list, "climb");
    }


    /**
     * 新增漫画爬虫
     */
    @GetMapping("/add")
    public String add(ModelMap map) {

        /*返回的数据*/
        LinkedHashMap<Long, String> mapMhNames = mhClimbService.mapMhNames();

        map.put("MhNameDataAll", mapMhNames);

        return prefix + "/add";
    }

    /**
     * 新增保存漫画爬虫
     */
    @RequiresPermissions("manhua:climb:add")
    @Log(title = "漫画爬虫", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MhClimb mhClimb) {
        return toAjax(mhClimbService.insertMhClimb(mhClimb));
    }

    /**
     * 修改漫画爬虫
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        MhClimb mhClimb = mhClimbService.selectMhClimbById(id);
        mmap.put("mhClimb", mhClimb);
        return prefix + "/edit";
    }

    /**
     * 修改保存漫画爬虫
     */
    @RequiresPermissions("manhua:climb:edit")
    @Log(title = "漫画爬虫", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MhClimb mhClimb) {
        return toAjax(mhClimbService.updateMhClimb(mhClimb));
    }

    /**
     * 删除漫画爬虫
     */
    @RequiresPermissions("manhua:climb:remove")
    @Log(title = "漫画爬虫", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(mhClimbService.deleteMhClimbByIds(ids));
    }
}
